// pages/leader_after/leader_after.js
var common = require("../../common/common.js").common;

Page({
    /**
   * 页面的初始数据
   */
    data: {
        nav: [ {
            id: 100,
            text: "全部"
        }, {
            id: 0,
            text: "申请中"
        }, {
            id: 1,
            text: "已同意"
        }, {
            id: 2,
            text: "已拒绝"
        } ],
        choose_nav: 100,
        clerk: [],
        page: 1,
        search: "",
        order: []
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        wx.hideShareMenu();
        let that = this;
        that.setData({
            clerk: wx.getStorageSync("clerk")
        });
        that.getData();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {
        this.getData();
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    //选择状态
    choose_nav: function(e) {
        let that = this;
        let id = e.currentTarget.dataset.id;
        this.setData({
            choose_nav: id,
            page: 1,
            order: []
        });
        that.getData();
    },
    //获取售后订单
    getData: function() {
        let that = this;
        var clerk = that.data.clerk;
        var openid = "";
        if (clerk.wom_status == 0) {
            openid = wx.getStorageSync("user").openid;
        } else {
            openid = clerk.leader_openid;
        }
        var page = that.data.page;
        let choose_nav = that.data.choose_nav;
        let search = that.data.search;
        common.request({
            endpoint: "Order/orderinfo/leaderafter2",
            method: "post",
            data: {
                openid: openid,
                page: page,
                verify_status: choose_nav,
                search: search
            },
            success: res => {
                var data = that.data.order;
                let order = page == 1 ? res.extra : data.concat(res.extra);
                if (res.extra.length > 0) {
                    that.setData({
                        order: order
                    });
                    that.data.page = page + 1;
                }
            }
        });
    },
    getValue: function(e) {
        var that = this;
        var search_con = e.detail.value;
        that.setData({
            search_con: search_con
        });
    },
    search: function(e) {
        var that = this;
        var clerk = that.data.clerk;
        var openid = "";
        if (clerk.wom_status == 0) {
            openid = wx.getStorageSync("user").openid;
        } else {
            openid = clerk.leader_openid;
        }
        var search_con = that.data.search_con;
        var choose_nav = that.data.choose_nav;
        common.request({
            endpoint: "Order/orderinfo/leaderafter2",
            method: "post",
            data: {
                openid: openid,
                search: search_con,
                verify_status: choose_nav
            },
            header: {
                "content-type": "application/json"
            },
            success: res => {
                that.setData({
                    order: res.extra
                });
            }
        });
    }
});